package com.poker.wiki.controller;


import com.github.pagehelper.PageInfo;
import com.poker.common.utils.Result;

import org.springframework.web.bind.annotation.*;
import com.poker.wiki.Service.CategoryService;
import com.poker.wiki.entity.Category;
import com.poker.wiki.req.CategoryQueryReq;
import com.poker.wiki.req.CategorySaveReq;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@RestController
@RequestMapping("")
public class CategoryController {
    @Resource
    CategoryService categoryService;

    @RequestMapping("getAllCategory")
    public Result getAllCategory() {
        List<Category> allCategory = categoryService.getAllCategory();
        return Result.success(allCategory);
    }

    @RequestMapping("findCategory")
    public Result findCategory(@Valid CategoryQueryReq req) {
        PageInfo<Category> pageInfo = categoryService.findCategory(req);
        return Result.success(pageInfo);
    }

    @DeleteMapping("/deleteCategory/{id}")
    public Result delete(@PathVariable Long id){
        categoryService.delete(id);
        return Result.success();
    }

    @PostMapping("/saveCategory")
    public Result save(@RequestBody @Valid CategorySaveReq req){
        categoryService.save(req);
        return Result.success();
    }
}
